home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / ifp1s158.zip / IFPCOMON.PAS < prev    next >
Pascal/Delphi Source File  |  1993-08-15  |  13KB  |  636 lines

  1. unit ifpcomon;
  2.  
  3. interface
  4.  
  5. uses Crt, Dos, ifpglobl, ifpextrn;
  6.  
  7. function getkey2: char2;
  8. function getnum: word;
  9. procedure caption1(a: string);
  10. procedure caption2(a: string);
  11. procedure caption3(a : string);
  12. function nocarry(regs: registers) : boolean;
  13. function hex(a : word; b : byte) : string;
  14. procedure unknown(a: string; b: word; c: byte);
  15. procedure yesorno(a : boolean);
  16. procedure yesorno2(a: boolean);
  17. procedure yesorno3(a: boolean);
  18. procedure dontknow;
  19. procedure dontknow2;
  20. procedure segofs(a, b : word);
  21. function showchar(a : char) : char;
  22. function power2(y: word): longint;
  23. procedure pause1;
  24. procedure pause2;
  25. procedure pause3(extra: integer);
  26. procedure pause4(direc: directions; var ch2: char2);
  27. procedure pause5(direc: directions; var ch2: char2);
  28. function bin4(a: byte) : string;
  29. procedure offoron(a: string; b: boolean);
  30. procedure zeropad(a: word);
  31. procedure zeropad3(a: word);
  32. procedure showvers;
  33. function cbw(a, b: byte) : word;
  34. function bin16(a: word) : string;
  35. procedure drvname(a: byte);
  36. procedure media(a, b: byte);
  37. procedure pagenameclr;
  38. procedure Intr(intno: byte; var regs: registers);
  39. procedure MsDos(var regs: registers);
  40. procedure TextColor(color: byte);
  41. procedure TextBackground(color: byte);
  42. function unBCD(b: byte): byte;
  43. function addzero(b: byte): string;
  44. procedure modeinfo(var vidmode, vidlen, vidpg: byte; var vidwid: word);
  45. procedure box;
  46. procedure center(s: string);
  47. function EMSOK: boolean;
  48.  
  49. implementation
  50.  
  51. uses ifpscrpt, ifphelp;
  52.  
  53. function getkey2: char2;
  54.   var
  55.     c: char;
  56.     c2: char2;
  57.  
  58.   begin
  59.   c:=ReadKey;
  60.   if c = #0 then
  61.     getkey2:=c + ReadKey
  62.   else
  63.     getkey2:=c;
  64.   end; {getkey2}
  65.  
  66. {^Make sure number entered, not any letters}
  67. function getnum: word;
  68.   var
  69.     inpchar: char;
  70.     number_string: string[2];
  71.     temp, position, code: word;
  72.     row, col: byte;
  73.     finish: boolean;
  74.  
  75.   begin
  76.   row:=WhereY;
  77.   col:=WhereX;
  78.   Write(' ':3);
  79.   GotoXY(col, row);
  80.   temp:=99;
  81.   finish:=false;
  82.   position:=0;
  83.   number_string:='';
  84.   TextColor(LightGray);
  85.   repeat
  86.     inpchar:=ReadKey;
  87.     case inpchar of
  88.       '0'..'9':if position < 2 then
  89.         begin
  90.         Inc(position);
  91.         Inc(number_string[0]);
  92.         number_string[position]:=inpchar;
  93.         Write(inpchar)
  94.         end;
  95.       #8: if position > 0 then
  96.         begin
  97.         Dec(position);
  98.         Dec(number_string[0]);
  99.         Write(^H' '^H)
  100.         end;
  101.       #27: if number_string = '' then
  102.           finish:=true
  103.         else
  104.           begin
  105.           number_string:='';
  106.           GotoXY(col, row);
  107.           ClrEol;
  108.           position:=0
  109.           end;
  110.       #13: finish:=true
  111.     end {case}
  112.   until finish;
  113.   if number_string <> '' then
  114.     Val(number_string, temp, code)
  115.   else
  116.     temp:=999;
  117.   getnum:=temp
  118.   end; {getnum}
  119.  
  120. procedure caption1(a: string);
  121.   begin
  122.   textcolor(LightGray);
  123.   Write(a);
  124.   textcolor(LightCyan)
  125.   end; {caption1}
  126.  
  127. procedure caption2(a: string);
  128.   const
  129.     capterm = ': ';
  130.  
  131.   var
  132.     i: byte;
  133.     xbool: boolean;
  134.  
  135.   begin
  136.   i:=length(a);
  137.   while (i > 0) and (a[i] = ' ') do
  138.     dec(i);
  139.   insert(capterm, a, i + 1);
  140.   caption1(a)
  141.   end; {caption2}
  142.  
  143. procedure caption3(a : string);
  144.   begin
  145.   caption2('  ' + a)
  146.   end; {caption3}
  147.  
  148. function nocarry(regs: registers) : boolean;
  149.   begin
  150.   nocarry:=regs.flags and fcarry = $0000
  151.   end; {nocarry}
  152.  
  153. function hex(a : word; b : byte) : string;
  154.   const
  155.     digit : array[$0..$F] of char = '0123456789ABCDEF';
  156.  
  157.   var
  158.     i : byte;
  159.     xstring : string;
  160.  
  161.   begin
  162.   xstring:='';
  163.   for i:=1 to b do
  164.     begin
  165.     insert(digit[a and $000F], xstring, 1);
  166.     a:=a shr 4
  167.     end;
  168.   hex:=xstring
  169.   end; {hex}
  170.  
  171. procedure unknown(a: string; b: word; c: byte);
  172.   begin
  173.   Writeln('(unknown', ' ', a, ' ', hex(b, c), ')')
  174.   end; {unknown}
  175.  
  176. procedure yesorno(a : boolean);
  177.   begin
  178.   if a then
  179.     Writeln('yes')
  180.   else
  181.     Writeln('no')
  182.   end; {yesorno}
  183.  
  184. procedure yesorno2(a: boolean);
  185.   begin
  186.   if a then
  187.     Write('yes')
  188.   else
  189.     Write('no')
  190.   end; {yesorno2}
  191.  
  192. procedure YesOrNo3(a: boolean);
  193.   begin
  194.   YesOrNo2(a);
  195.   if not a then
  196.     Write(' ');
  197.   end;
  198.  
  199. procedure dontknow;
  200.   begin
  201.   Writeln('(unknown)')
  202.   end; {dontknow}
  203.  
  204. procedure dontknow2;
  205.   begin
  206.   Write('(unknown)')
  207.   end; {dontknow2}
  208.  
  209. procedure segofs(a, b : word);
  210.   begin
  211.   Write(hex(a, 4), ':', hex(b, 4))
  212.   end; {segofs}
  213.  
  214. function showchar(a : char) : char;
  215.   begin
  216.   if a in pchar then
  217.     showchar:=a
  218.   else
  219.     showchar:='.'
  220.   end; {showchar}
  221.  
  222. function power2(y: word): longint;
  223.   begin
  224.   power2:=Trunc(exp((y * 1.0) * ln(2.0)))
  225.   end;
  226.  
  227. procedure pause1;
  228.   var
  229.     xbyte : byte;
  230.     xchar : char2;
  231.     SaveX, SaveY: byte;
  232.  
  233.   begin
  234.   xbyte:=TextAttr;
  235.   endit:=false;
  236.   TextColor(Cyan);
  237.   SaveX:=WhereX;
  238.   SaveY:=WhereY;
  239.   Write('( for more)');
  240.   if PrinterRec.Mode = 'A' then
  241.     ScreenPrint(Pg, PgNames[Pg], VerNum)
  242.   else
  243.     begin
  244.     repeat
  245.       xchar:=getkey2;
  246.       if xchar = #0#25 then
  247.         begin
  248.         ScreenPrint(Pg, PgNames[Pg], VerNum);
  249.         xchar:=#0#0
  250.         end;
  251.       if xchar = #0#$3B then
  252.         begin
  253.         HelpScreen(Pg, HelpVersion);
  254.         xchar:=#0#0
  255.         end;
  256.     until xchar <> #0#0;
  257.     if xchar <> #0#80 then
  258.       begin
  259.       endit:=true;
  260.       c2:=xchar
  261.       end;
  262.     end;
  263.   TextAttr:=xbyte;
  264.   GotoXY(SaveX, SaveY);
  265.   Write('            ')
  266.   end; {pause1}
  267.  
  268. procedure pause2;
  269.   var
  270.     xbyte : byte;
  271.  
  272.   begin
  273.   if WhereY + hi(WindMin) > hi(WindMax) then
  274.     begin
  275.     xbyte:=TextAttr;
  276.     TextColor(Cyan);
  277.     pause1;
  278.     if not endit then
  279.       begin
  280.       Clrscr;
  281.       Writeln('(continued)');
  282.       end;
  283.     TextAttr:=xbyte
  284.     end
  285.   end; {pause2}
  286.  
  287. procedure pause3(extra: integer);
  288.   var
  289.     xbyte: byte;
  290.   begin
  291.   endit:=false;
  292.   if WhereY + Hi(WindMin) + Abs(extra) > Hi(WindMax) then
  293.     begin
  294.     xbyte:=TextAttr;
  295.     TextColor(Cyan);
  296.     pause1;
  297.     if not endit then
  298.       begin
  299.       ClrScr;
  300.       if extra < 0 then
  301.         Writeln('(continued)');
  302.       end;
  303.     TextAttr:=xbyte
  304.     end
  305.   end; {pause3}
  306.  
  307. procedure pause4(Direc: Directions; var ch2: char2);
  308.   var
  309.     xbyte : byte;
  310.     xchar : char2;
  311.     SaveX, SaveY: byte;
  312.  
  313.   begin
  314.   xbyte:=TextAttr;
  315.   endit:=false;
  316.   TextColor(Cyan);
  317.   SaveX:=WhereX;
  318.   SaveY:=WhereY;
  319.   case Direc of
  320.     none:   Write('(any key)');
  321.     up:     Write('( for more)');
  322.     down:   Write('( for more)');
  323.     updown: Write('( or  for more)')
  324.   end;
  325.   repeat
  326.     if PrinterRec.Mode = 'A' then
  327.       if Direc = up then
  328.         xchar:=#0#81
  329.       else
  330.         begin
  331.         ScreenPrint(Pg, PgNames[Pg], VerNum);
  332.         xchar:=#0#80;
  333.         end
  334.     else
  335.       begin
  336.       xchar:=getkey2;
  337.       if xchar = #0#25 then
  338.         begin
  339.         ScreenPrint(Pg, Pgnames[Pg], VerNum);
  340.         xchar:=#0#0
  341.         end;
  342.       if xchar = #0#$3B then
  343.         begin
  344.         HelpScreen(Pg, HelpVersion);
  345.         xchar:=#0#0
  346.         end;
  347.       end;
  348.   until xchar <> #0#0;
  349.   if (xchar[1] <> #0) or
  350.     ((xchar[1] = #0) and (not (xchar[2] in [#80, #72]))) then
  351.     begin
  352.     endit:=true;
  353.     c2:=xchar;
  354.     end;
  355.   TextAttr:=xbyte;
  356.   GotoXY(SaveX, SaveY);
  357.   Write('                 ');
  358.   ch2:=xchar;
  359.   end; {pause4}
  360.  
  361. procedure pause5(direc: directions; var ch2: char2);
  362.   var
  363.     xbyte : byte;
  364.  
  365.   begin
  366.   ch2:=#0#0;
  367.   if WhereY + Hi(WindMin) > Hi(WindMax) then
  368.     begin
  369.     xbyte:=TextAttr;
  370.     TextColor(Cyan);
  371.     Pause4(direc, ch2);
  372.     if not endit then
  373.       Clrscr;
  374.     TextAttr:=xbyte
  375.     end
  376.   end; {pause5}
  377.  
  378. function bin4(a : byte) : string;
  379.   const
  380.     digit : array[0..1] of char = '01';
  381.  
  382.   var
  383.     xstring : string;
  384.     i : byte;
  385.  
  386.   begin
  387.   xstring:='';
  388.   for i:=3 downto 0 do
  389.     begin
  390.     insert(digit[a mod 2], xstring, 1);
  391.     a:=a shr 1
  392.     end;
  393.   bin4:=xstring
  394.   end; {bin4}
  395.  
  396. procedure offoron(a : string; b : boolean);
  397.   begin
  398.   caption3(a);
  399.   if b then
  400.     Write('on')
  401.   else
  402.     Write('off')
  403.   end; {offoron}
  404.  
  405. procedure zeropad(a : word);
  406.   begin
  407.   if a < 10